<div class="layui-fluid layui-anim website-anim-up" id="website-user-applicant-update" lay-title="修改用户信息">
    <div class="layui-row layui-col-space8 website-container">
        <div class="layui-col-md12 layui-col-sm12 layui-col-xs12">
            <form class="layui-form" lay-filter="user-applicant-update" id="user-applicant-update">
                <div class="layui-form-item">
                    <div class="layui-row">
                        <div class="website-hide">
                            <label class="layui-form-label website-form-item-require">用户id：</label>
                            <div class="layui-input-block">
                                <input type="text" name="applicantId" data-th-value="${applicantId}">
                            </div>
                        </div>
                        <!-- 基本信息-->
                        <div class="layui-inline layui-col-xs5 layui-col-sm5 layui-col-md5">
                            <label class="layui-form-label website-form-item-require">姓名</label>
                            <div class="layui-input-block">
                                <input type="text" name="name" lay-verify="required" maxlength="20" autocomplete="off"
                                       class="layui-input">
                            </div>
                        </div>
                        <div class=" layui-inline layui-col-xs5 layui-col-sm5 layui-col-md5 layui-col-md-offset1 layui-col-lg-offset1">
                            <label class="layui-form-label">民族</label>
                            <div class="layui-input-block">
                                <select name="nationTypeCode"
                                        lay-filter="nationTypeCode">
                                    <option value="">请选择</option>
                                    <option
                                            th:each="item : ${nation}"
                                            th:value="${item.code}" th:text="${item.name}">
                                    </option>
                                </select>
                            </div>
                        </div>
                    </div>
                    <div class="layui-row">
                        <div class="layui-inline layui-col-xs5 layui-col-sm5 layui-col-md5">
                            <label class="layui-form-label">性别</label>
                            <div class="layui-input-block">
                                <select name="sexTypeCode" lay-verify="required" lay-filter="sexTypeCode">
                                    <option value="">请选择</option>
                                    <option
                                            th:each="item : ${sex}"
                                            th:value="${item.code}" th:text="${item.name}">
                                    </option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline layui-col-xs5 layui-col-sm5 layui-col-md5 layui-col-md-offset1 layui-col-lg-offset1">
                            <label class="layui-form-label website-form-item-require">行政职务</label>
                            <div class="layui-input-block">
                                <select name="positionTypeCode" lay-verify="required"
                                        lay-filter="positionTypeCode">
                                    <option value="">请选择</option>
                                    <option
                                            th:each="item : ${positionTypeCode}"
                                            th:value="${item.code}" th:text="${item.name}">
                                    </option>
                                </select>
                            </div>
                        </div>
                    </div>
                    <div class="layui-row">
                        <div class=" layui-inline layui-col-xs5 layui-col-sm5 layui-col-md5 ">
                            <label class="layui-form-label website-form-item-require">职称级别</label>
                            <div class="layui-input-block">
                                <select name="titleTypeCode" lay-verify="required"
                                        lay-filter="titleTypeCode">
                                    <option value="">请选择</option>
                                    <option
                                            th:each="item : ${titleTypeCode}"
                                            th:value="${item.code}" th:text="${item.name}">
                                    </option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline layui-col-xs5 layui-col-sm5 layui-col-md5 layui-col-md-offset1 layui-col-lg-offset1">
                            <label class="layui-form-label website-form-item-require">职称</label>
                            <div class="layui-input-block">
                                <input type="text" name="professionCode" lay-verify="required" maxlength="50"
                                       autocomplete="off" class="layui-input">
                            </div>
                        </div>
                    </div>
                    <div class="layui-row">
                        <div class="layui-inline layui-col-xs5 layui-col-sm5 layui-col-md5">
                            <label class="layui-form-label">工作单位</label>
                            <div class="layui-input-block">
                                <input type="text" name="company" autocomplete="off" maxlength="100"
                                       class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline layui-col-xs5 layui-col-sm5 layui-col-md5  layui-col-md-offset1 layui-col-lg-offset1   ">
                            <label class="layui-form-label">担任导师</label>
                            <div class="layui-input-block">
                                <select name="tutorTypeCode" lay-filter="tutorTypeCode">
                                    <option value="">请选择</option>
                                    <option
                                            th:each="item : ${tutor}"
                                            th:value="${item.code}" th:text="${item.name}">
                                    </option>
                                </select>
                            </div>
                        </div>
                    </div>
                    <div class="layui-row">
                        <div class="layui-inline layui-col-xs5 layui-col-sm5 layui-col-md5">
                            <label class="layui-form-label">座机</label>
                            <div class="layui-input-block">
                                <input type="text" name="telephone" lay-verify="tellphone" autocomplete="off"
                                       class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline layui-col-xs5 layui-col-sm5 layui-col-md5 layui-col-md-offset1 layui-col-lg-offset1">
                            <label class="layui-form-label">通讯地址</label>
                            <div class="layui-input-block">
                                <input type="text" name="address" autocomplete="off" maxlength="100"
                                       class="layui-input">
                            </div>
                        </div>
                    </div>
                    <div class="layui-row">
                        <div class="layui-inline layui-col-xs5 layui-col-sm5 layui-col-md5">
                            <label class="layui-form-label website-form-item-require">手机</label>
                            <div class="layui-input-block">
                                <input type="text" name="mobile" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline layui-col-xs5 layui-col-sm5 layui-col-md5 layui-col-md-offset1 layui-col-lg-offset1">
                            <label class="layui-form-label">政治面貌</label>
                            <div class="layui-input-block">
                                <select name="politicalTypeCode" lay-filter="politicalTypeCode">
                                    <option value="">请选择</option>
                                    <option
                                            th:each="item : ${political}"
                                            th:value="${item.code}" th:text="${item.name}">
                                    </option>
                                </select>
                            </div>
                        </div>
                    </div>
                    <div class="layui-row">
                        <div class="layui-inline layui-col-xs5 layui-col-sm5 layui-col-md5">
                            <label class="layui-form-label website-form-item-require">证件类型</label>
                            <div class="layui-input-block">
                                <select id="identityTypeCode" name="identityTypeCode" lay-filter="identityTypeCode"
                                        lay-verify="required">
                                    <option value="">请选择</option>
                                    <option
                                            th:each="item : ${identityTypeCode}"
                                            th:value="${item.code}" th:text="${item.name}">
                                    </option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline layui-col-xs5 layui-col-sm5 layui-col-md5 layui-col-md-offset1 layui-col-lg-offset1">
                            <label id="identity-label" class="layui-form-label website-form-item-require">证件号码</label>
                            <div class="layui-input-block">
                                <!--                                lay-verify="required|identity"-->
                                <input type="text" id="identity" name="identity" lay-verify="required"
                                       autocomplete="off" class="layui-input" maxlength="30">
                            </div>
                        </div>
                    </div>
                    <div class="layui-row">
                        <div class="layui-form-item layui-inline layui-col-xs5 layui-col-sm5 layui-col-md5">
                            <label class="layui-form-label">最终学位</label>
                            <div class="layui-input-block">
                                <select name="degreeTypeCode" lay-filter="degreeTypeCode">
                                    <option value="">请选择</option>
                                    <option
                                            th:each="item : ${degree}"
                                            th:value="${item.code}" th:text="${item.name}">
                                    </option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline layui-col-xs5 layui-col-sm5 layui-col-md5 layui-col-md-offset1 layui-col-lg-offset1">
                            <label class="layui-form-label website-form-item-require">邮箱</label>
                            <div class="layui-input-block">
                                <input type="text" name="email" readonly lay-verify="required|email" maxlength="50"
                                       autocomplete="off" class="layui-input">
                            </div>
                        </div>
                    </div>
                    <div class="layui-row">
                        <div class="layui-inline layui-col-xs5 layui-col-sm5 layui-col-md5">
                            <label class="layui-form-label">外语语种</label>
                            <div class="layui-input-block">
                                <select name="language" lay-filter="language">
                                    <option value="">请选择</option>
                                    <option
                                            th:each="item : ${language}"
                                            th:value="${item.code}" th:text="${item.name}">
                                    </option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline layui-col-xs5 layui-col-sm5 layui-col-md5 layui-col-md-offset1 layui-col-lg-offset1">
                            <label class="layui-form-label website-form-item-require">出生日期</label>
                            <div class="layui-input-block">
                                <input type="text" lay-verify="required" id="birthday" name="birthday"
                                       autocomplete="off" class="layui-input">
                            </div>
                        </div>
                    </div>

                    <div class="layui-form-item website-hide">
                        <button class="layui-btn" lay-submit="" lay-filter="user-applicant-update-form-submit"
                                id="submit">保存
                        </button>
                        <button class="layui-btn layui-btn-warm" id="clean">取消</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>

<script data-th-inline="javascript" type="text/javascript">
    layui.use(['dropdown', 'jquery', 'laydate', 'form', 'website'], function () {
        let $ = layui.jquery,
            laydate = layui.laydate,
            website = layui.website,
            form = layui.form,
            $form = $('#user-applicant-update'),
            view = layui.view,
            dropdown = layui.dropdown,
            $view = $('#website-user-applicant-update'),
            $submit = $('#submit'),
            result = [[${result}]],
            $clean = $view.find('#clean');
        // 重新渲染 form否则不会显示下拉框
        form.render();
        initForm();

        function initForm() {
            if (result) {
                form.val("user-applicant-update", {
                    "applicantId": result.applicantId,
                    "name": result.name,
                    "nationTypeCode": result.nationTypeCode,
                    "sexTypeCode": result.sexTypeCode,
                    "positionTypeCode": result.positionTypeCode,
                    "titleTypeCode": result.titleTypeCode,
                    "email": result.email,
                    "tutorTypeCode": result.tutorTypeCode,
                    "company": result.company,
                    "telephone": result.telephone,
                    "address": result.address,
                    "mobile": result.mobile,
                    "politicalTypeCode": result.politicalTypeCode,
                    "identity": result.identity,
                    "professionCode": result.professionCode,
                    "language": result.language,
                    "identityTypeCode": result.identityTypeCode,
                    "birthday": result.birthday,
                    "degreeTypeCode": result.degreeTypeCode
                });
                if (result.identity) {
                    $('#identity').attr('readonly', 'readonly')
                }
                if ("zjlx_sfz" === result.identityTypeCode) {
                    $('#identity')[0].setAttribute('lay-verify', "required|identity")
                }else if (result.identityTypeCode){
                    $('#identity')[0].setAttribute('lay-verify', "required")
                }
            }
        }

        form.on('submit(user-applicant-update-form-submit)', function () {
            let params = $form.serializeJson();
            website.post(ctx + 'applicantInfo/update/' + params.applicantId, params, function () {
                layer.closeAll()
            });
        })

        laydate.render({
            //
            elem: '#birthday', //指定元素
            type: 'date',
            max: 0
        })

        form.on('select(identityTypeCode)', function (data) {
            if ("zjlx_sfz" === data.value) {
                // lay-verify="required|identity"
                $('#identity')[0].setAttribute('lay-verify', "required|identity")
            }else if (data.value){
                $('#identity')[0].setAttribute('lay-verify', "required")
            }
        });

    })


</script>